package com.dingyx.ps.redis;

import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

public abstract class RedisTemplateDao {

    @Resource
    protected RedisTemplate<String, String> redisTemplate;

    public ValueOperations<String, String> getValue(){
        return redisTemplate.opsForValue();
    }

    public ListOperations<String, String> getList(){
        return redisTemplate.opsForList();
    }

    public void expire(String key, long timeout){
        TimeUnit unit = TimeUnit.SECONDS;
        redisTemplate.expire(key, timeout, unit);
    }

    public boolean exists(String key) {
        return this.redisTemplate.hasKey(key);
    }

    public void expire(String key, long timeout, TimeUnit unit){
        redisTemplate.expire(key, timeout, unit);
    }

}
